﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.ComponentModel;
using Ahi.Properties;
using MongoDB.Bson;
using Ahi.Entity;
using System.Windows.Forms;

namespace Ahi.Config
{
    public class AppConfig
    {
        #region Singleton
        private static AppConfig _current;
        public static AppConfig Current
        {
            get
            {
                if (_current == null)
                    _current = new AppConfig();
                return _current;
            }
        }

        public ObjectId Id { get; set; }

        private AppConfig()
        {
            Id = new ObjectId("4bea15463302000000006dd0");
        }
        #endregion

        public void SaveToXml()
        {
            Settings.Default.Save();
        }

        public void SaveToDatabase()
        {
            MongoAdaptor.Instance.Save<AppConfig>(this);
        }

        public void LoadFromDatabase()
        {
            _current = MongoAdaptor.Instance.GetDataById<AppConfig>(this.Id);
        }

        public ObjectId UyelerRaporu { get; set; }

        public ObjectId ToplantiRaporu { get; set; }

        public string KullaniciAdi
        {
            get
            {
                return Settings.Default.KullaniciAdi;
            }
            set
            {
                Settings.Default.KullaniciAdi = value;
            }
        }

        public string VeritabaniSunucusu
        {
            get
            {
                return Settings.Default.VeritabaniYolu;
            }
            set
            {
                Settings.Default.VeritabaniYolu = value;
            }
        }

        public string UygulamaDizini
        {
            get
            {
                return AppDomain.CurrentDomain.BaseDirectory;
            }
        }

        public string MongoDBDizini
        {
            get
            {
#if DEBUG
                return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MongoDb/Server");
#else
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ahi Dernek\\mongo bin");
#endif
            }
        }

        public string DataDiziniDizini
        {
            get
            {
#if DEBUG
                return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "MongoDb/Data/db");
#else
                return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ahi Dernek\\data");
#endif
            }
        }

        [MongoDB.Bson.Serialization.Attributes.BsonIgnore]
        public string ConnectionString
        {
            get
            {
                return string.Format("mongodb://{0}/Dernek", VeritabaniSunucusu);
            }
        }

        public ObjectId KomisyonRaporu { get; set; }

        public string LogTxtDosyasi
        {
            get
            {
                return Path.Combine(LogDirectory, TextLogAdi);
            }
        }

        //public Dictionary<string, string> FormLayouts { get; set; }

        //public Dictionary<string, string> GridLayouts { get; set; }

        public string LayoutDizini
        {
            get
            {
                return Path.Combine(UygulamaDizini, "Layouts");
            }
        }

        public ObjectId IsArayanlarRaporu { get; set; }

        public ObjectId PersonelArayanlarRaporu { get; set; }

        public DevExpress.Skins.SkinContainer Tema { get; set; }

        public string VarsayilanTema { get; set; }

        public ObjectId EtkinliklerRaporu { get; set; }

        public string LogDirectory
        {
            get
            {
                return Path.Combine(this.UygulamaDizini, "Log");
            }
        }

        public string TextLogAdi
        {
            get
            {
                return "Log.txt";
            }
        }

        public object AppName
        {
            get
            {
                return "Ahi Dernek Yönetim";
            }
        }

        public object AppVersion
        {
            get
            {
                return "0.1.1";
            }
        }
    }
}
